﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace insert_adap
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=(local);Initial Catalog=sale; User Id=sa; Password=sa";
            SqlDataAdapter da = new SqlDataAdapter();
            SqlCommand secmd = new SqlCommand("select * from customers", conn);
            SqlCommand incmd = new SqlCommand("insert into customers values(@id,@name)", conn);
            incmd.Parameters.Add("@id", SqlDbType.Int, 4, "id");
            incmd.Parameters.Add("@name", SqlDbType.NVarChar, 30, "name");

            da.SelectCommand = secmd;
            da.InsertCommand = incmd;

            DataSet ds = new DataSet();
            da.Fill(ds, "customers");
            DataTable dt = ds.Tables["customers"];
            DataRow row = dt.Rows.Add();
            row[0] = 2;
            row[1] = "Nguyen Ai Quoc";
            da.Update(ds, "customers");
        }
    }

}
    
